package com.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.entity.Cashier;
import com.entity.Doctor;
import com.entity.Prescriptiondetail;
import com.mapper.CashierMapper;
import com.mapper.DoctorMapper;
import com.mapper.PrescriptiondetailrMapper;
import com.service.CashierService;
import com.service.DoctorService;
import com.untils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CashierServiceImpl extends ServiceImpl<CashierMapper, Cashier> implements CashierService {
    @Autowired
    CashierMapper cashierMapper;

    @Autowired
    PrescriptiondetailrMapper prescriptiondetailrMapper;

    @Override
    public String login_cashier(Cashier cashier){
        System.out.println("进入login_cashier");
        List<Cashier> selectedList = list(new LambdaQueryWrapper<Cashier>()
                .eq(Cashier::getCashierId, cashier.getCashierId()));
        if (selectedList.isEmpty()) {
            throw new RuntimeException("账号不存在哦 请先注册吧~");
        }
        Cashier selected = selectedList.get(0);
        String encodedPassword = selected.getPsw();
        if (!cashier.getPsw().equals(encodedPassword)) {
            throw new RuntimeException("账号或密码有误 请再检查检查~");
        }
        // 生成令牌
        HashMap<String, Object> map = new HashMap<>(2);
        map.put("CashierId", selected.getCashierId());
        map.put("psw", selected.getPsw());
        System.out.println("返回令牌，令牌为：" + JwtUtil.generateToken(map));
        return JwtUtil.generateToken(map);
    }

    @Override
    public List<Map<String, Object>> liquidation(){
        System.out.println("进入liquidation");
        return prescriptiondetailrMapper.liquidation();
    }

    @Override
    public void updateP(Prescriptiondetail prescriptiondetail){
        System.out.println("进入updateP"+prescriptiondetail);
        prescriptiondetailrMapper.updateP(prescriptiondetail.getPrescriptionDetailId());
    }

    @Override
    public List<Map<String, Object>> getDaily(Prescriptiondetail prescriptiondetail){
        System.out.println("进入getList"+prescriptiondetail);
        return prescriptiondetailrMapper.getDaily(prescriptiondetail.getPrescriptionDetailId());
    }

    @Override
    public List<Map<String, Object>> getDailyDrug(Prescriptiondetail prescriptiondetail){
        System.out.println("进入getDailyDrug"+prescriptiondetail);
        return prescriptiondetailrMapper.getDailyDrug(prescriptiondetail.getPrescriptionDetailId());
    }
}
